package com.base.cn.platform.os.controller.web.classes.topic.reply;

import com.base.cn.platform.os.common.WebBaseController;
import com.base.cn.platform.os.service.course.classes.topic.reply.ClassesTopicReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Map;

/**
 * 班级话题评论
 *
 * @author SK
 * @since 2018-05-31
 */
@Controller
@RequestMapping("/web/classes/topic")
public class WebClassesTopicReplyController extends WebBaseController {

    @Autowired
    private ClassesTopicReplyService classesTopicReplyService;

    /**
     * 加载话题评论列表
     *
     * @param params 话题评论查询参数
     * @return 话题评论列表
     */
    @RequestMapping("/ajaxTopicReplyList")
    public String ajaxTopicReplyList(Model model,
                                     @RequestBody Map<String, Object> params,
                                     @RequestParam(value = "currentPage", required = false, defaultValue = "1") Integer currentPage) {
        Map<String, Object> dataMap = classesTopicReplyService.findClassesTopicReplyListPage(params, currentPage, null, true, true, false,true);
        model.addAttribute("dataMap", dataMap);
        return resultPage("/classes/topic/reply/ajax-topic-reply-list");
    }

    /**
     * 保存话题评论
     *
     * @param params 话题评论
     * @return 保存结果
     */
    @RequestMapping("/saveTopicReply")
    @ResponseBody
    public Map<String, Object> saveTopicReply(HttpServletRequest request,
                                              @RequestBody Map<String, Object> params) {
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        params.put("userId", userId);
        return classesTopicReplyService.saveClassesTopicReply(params, true);
    }
}
